package com.example.cinema.database;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class AppDataBase extends SQLiteOpenHelper {
    //轮播海报
    private String sql = "CREATE TABLE  IF NOT EXISTS `poster` (" +
            "`image` TEXT, " +
            "`urls` TEXT, " +
            "`apskk` TEXT, " +
            "`types` TEXT" +
            ")";
    //视频数据
    private String sql1 = "CREATE TABLE IF NOT EXISTS `videom3u8`(" +
            "`videosid`  INT PRIMARY KEY, " +
            "`videoname` VARCHAR(250)," +
            "`videotype` VARCHAR(250) ," +
            "`videotime` LONGTEXT ," +
            "`videopath` LONGTEXT ," +
            "`videobrief` LONGTEXT ," +
            "`videogif` LONGTEXT ," +
            "`videoimg` LONGTEXT," +
            "`videotag` LONGTEXT," +
            "`videocover` LONGTEXT," +
            "`videouser` VARCHAR(250)," +
            "`videousid` VARCHAR(250)," +
            "`videopart` LONGTEXT," +
            "`videouimg` LONGTEXT,"+
            "`videolove` INT)";
    //视频分类
    private String sql2 = "CREATE TABLE  IF NOT EXISTS `videotype`(`typeid`  LONGTEXT PRIMARY KEY ,`typename` VARCHAR(250),`typenume` LONGTEXT)";
    //公告通知
    private String sql3 = "CREATE TABLE IF NOT EXISTS `notice`(`noticetitle` LONGTEXT PRIMARY KEY,`noticetexts` LONGTEXT)";
    //主播表
    private String sql4 = "CREATE TABLE IF NOT EXISTS `livertmp`(" +
                            "`livesid` VARCHAR(250)," +
                            "`livepath` LONGTEXT," +
                            "`liverelay` LONGTEXT," +
                            "`livetype` VARCHAR(250)," +
                            "`livename` VARCHAR(255)," +
                            "`livestate` CHAR(1)," +
                            "`livecover` LONGTEXT," +
                            "`livetext` LONGTEXT," +
                            "`livetag` LONGTEXT," +
                            "PRIMARY KEY (`livesid`)" +
                            ")";
    //VIP充值表
    private String sql6 = "CREATE TABLE IF NOT EXISTS `vipmoney`(" +
                    "`viptitle` VARCHAR(250),"+
                    "`vipmoney`  VARCHAR(250),"+
                    "`vipmasg` LONGTEXT,"+
                    "PRIMARY KEY (`vipmoney`)"
                    +")";
    //下载地址及背景图片
    private String sql5 = "CREATE TABLE IF NOT EXISTS  `dowtable`(`url` LONGTEXT,`img` LONGTEXT,PRIMARY KEY(`url`))";

    //用户账号密码信息保存
    private String sql7 = "CREATE TABLE IF NOT EXISTS `userinfo`(" +
            "`usersid` VARCHAR(250)," +
            "`useralias` VARCHAR(250)," +
            "`username` VARCHAR(250),"+
            "`userpswd` VARCHAR(250),"+
            "`userimg` LONGTEXT,"+
            "`usertime` LONGTEXT,"+
            "`userfree` INT,"+
            "PRIMARY KEY (`usersid`)"+
            ")";

    private String sql8 = "CREATE TABLE IF NOT EXISTS  `adverdata`(`adverurl` LONGTEXT,`adverskip` LONGTEXT)";
    private String sql9 = "CREATE TABLE IF NOT EXISTS  `adverdatas`(`adverurl` LONGTEXT,`adverskip` LONGTEXT)";

    public AppDataBase(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public AppDataBase(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version, @Nullable DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(sql1);
        db.execSQL(sql);
        db.execSQL(sql2);
        db.execSQL(sql3);
        db.execSQL(sql4);
        db.execSQL(sql5);
        db.execSQL(sql6);
        db.execSQL(sql7);
        db.execSQL(sql8);
        db.execSQL(sql9);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL(sql);
        db.execSQL(sql1);
        db.execSQL(sql2);
        db.execSQL(sql3);
        db.execSQL(sql4);
        db.execSQL(sql5);
        db.execSQL(sql6);
        db.execSQL(sql7);
        db.execSQL(sql8);
        db.execSQL(sql9);
        onCreate(db);
    }
}
